package com.sohu.tv.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sohu.tv.cache.RedisDao;
import com.sohu.tv.entity.UserInfo;
import com.sohu.tv.service.UserService;

@Controller
@RequestMapping(value="/rest")
public class UserController {
	
	@Resource
	UserService infoDao;
	@Resource
	RedisDao redisDao;
	
	
	@RequestMapping(value="/userinfo",method=RequestMethod.GET)
	@ResponseBody
	public Map<String,Object> userInfo(String access_token,String openId){
		Map<String,Object> result = new HashMap<String,Object>();
		//对access_token进行校验，如果没有失效则访问数据
		String aliveToken = redisDao.getToken(openId);
		if(access_token.equals(aliveToken)){
			int uid = redisDao.getUid(aliveToken);
			UserInfo info = infoDao.queryByUserId(uid);
			result.put("data", info);
			result.put("status", 200);
			result.put("message", "OK");
			return result;
		}
		result.put("status", -1);
		result.put("message", "ERROR");
		return result;
	}
}
